<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="true" title="社团报名" back-icon-color='#333333' height="50" :border-bottom="false">
			<view class="" style="margin-left: 600rpx; display: flex;align-content: center;"
				@click="$toLink('../append_club/append_club',{})">
				<image src="../../static/tupian96.png" mode="widthFix" style="width: 30rpx;"></image>
			</view>
		</u-navbar>
		<view class="" style="width:100%; height:2rpx; border:2rpx solid #F2F2F2;">
		</view>
		<view class="list">
			<view class="club_list" v-for="(item,index) in applyList" :key="index">
				<view class="top">
					<text>{{item.name}}</text>
					<text>{{item.startTime}}</text>
				</view>
				<view class="teacher">
					<image src="../../static/tupian114.png" mode="widthFix"></image>
					<text>{{item.handle_teacher_user_info?item.handle_teacher_user_info.full_name:''}}</text>
				</view>
				<view class="proprieter">
					<image src="../../static/tupian130.png" mode="widthFix"></image>
					<text>社长{{item.handle_student_user_info?item.handle_student_user_info.full_name:''}}</text>
				</view>

				<view class="bottom">
					<image src="../../static/tupian104.png" mode="widthFix"></image>
					<text>{{item.desc}}</text>
					<image src="../../static/tupian88.png" mode="widthFix" @click.stop="$toLink('../edit_club/edit_club',{id:item.league_id,teacher:item.handle_teacher_user_info?item.handle_teacher_user_info.full_name:'',header:item.handle_student_user_info?item.handle_student_user_info.full_name:'',student:item.student_users?item.student_users.full_name:'',
						club:item.name,desc:item.desc,require:item.require,student_user_id:item.handle_student_user_id,teacher_user_id:item.handle_teacher_user_id,clubId:item.student_users_ids,clubName:item.student_users?item.student_users
.full_name:''

})">
					</image>
				</view>
			</view>
			<view class="blank" style="width: 100%; height: 25rpx;">
			</view>
		</view>
		<u-loadmore :status="status" />
	</view>
</template>

<script>
	import request from '../../request.js'
	import time from '../../time.js'
	export default {
		data() {
			return {
				apply_list: [],
				status: 'loading',
				page: 0,
				last_page: '',
			}
		},
		onLoad() {
			this.leagueLists();
		},
		onReachBottom() { //滚动到底部触发该函数
			console.log('触发了吗')
			if (this.page >= this.last_page) {
				this.status = 'nomore';
				return
			} else {
				this.status = 'loading';
			} //如果大于最后一页那么就中断函数

			this.page = ++this.page;

			setTimeout(() => {
				this.leagueLists(this.page);
			}, 2000)
		},
		computed: {
			applyList() {
				if (this.apply_list) {
					this.apply_list.forEach(item => {
						this.$set(item, 'startTime', time.format(item.create_time));
					})
					return this.apply_list;
				} else {
					return [];
				}
			}
		},
		methods: {
			leagueLists(param) {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let pagination = param ? param : 1;
				let _this = this;
				request({
					url: base_url + 'teacher/league/lists',
					method: 'post',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data.data);
							console.log(res);
							console.log(res.data.data.data, res.data.data.last_page);
							_this.last_page = res.data.data.last_page;
							if (res.data.data.total == 0) {
								console.log('又触发吗');
								_this.status = 'nomore'
								//如果接口返回的数据为零的话，那么就中断函数
								_this.apply_list.length = 0;
								//没有数据的话那么就将数组清空
								_this.apply_list = [];
								return;
							};
							//页数为1的情况
							if (pagination == 1) {
								//先将原数组清空
								_this.apply_list = [];
								console.log('进来了吗');
								if (res.data.data.data == null) {
									console.log('执行到这了吗')
									_this.apply_list = [];
								} else {
									_this.apply_list = res.data.data.data;
								}
								console.log(_this.apply_list);
								_this.page = 1;
								if (pagination >= _this.last_page) {
									_this.status = 'nomore'
									return
								}
								//页数大于1的情况
							} else if (pagination > 1) {
								console.log(res.data.data.data);
								if (res.data.data.data == null) {
									_this.status = 'nomore'
								}
								_this.apply_list = [..._this.apply_list, ...res.data.data.data];
								console.log(_this.apply_list);
								if (pagination >= _this.last_page) {
									_this.status = 'nomore'
									return
								}
							}
							console.log(_this.apply_list, _this.apply_list[0].student_users_ids);
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
		}

	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		overflow: hidden;

		.list {
			width: 100%;
			overflow: hidden;

			.club_list {
				width: 710rpx;
				border-radius: 12rpx;
				margin-top: 20rpx;
				height: 224rpx;
				margin-left: 20rpx;
				box-shadow: 0px 1px 1px 1px #ccc;

				.top {
					width: 100%;
					height: 65rpx;
					display: flex;
					justify-content: flex-start;

					text {
						margin-top: 30rpx;

						&:nth-child(1) {
							color: #333333;
							font-size: 30rpx;
							width: 430rpx;
							margin-left: 20rpx;
						}

						&:nth-child(2) {
							color: #999999;
							font-size: 20rpx;
							margin-top: 33rpx;
							width: 240rpx;
						}
					}
				}

				.teacher {
					width: 100%;
					height: 50rpx;
					display: flex;
					justify-content: flex-start;

					image {
						&:nth-child(1) {
							margin-top: 20rpx;
							width: 22rpx;
							margin-left: 20rpx;
						}
					}

					text {
						&:nth-child(2) {
							margin-top: 13rpx;
							font-size: 24rpx;
							color: #666666;
							margin-left: 30rpx;
						}
					}
				}

				.proprieter {
					width: 100%;
					height: 50rpx;
					display: flex;
					justify-content: flex-start;

					image {
						&:nth-child(1) {
							margin-top: 20rpx;
							width: 22rpx;
							margin-left: 20rpx;
						}
					}

					text {
						&:nth-child(2) {
							margin-top: 13rpx;
							font-size: 24rpx;
							color: #666666;
							margin-left: 30rpx;
						}
					}
				}

				.bottom {
					width: 100%;
					height: 50rpx;
					display: flex;
					justify-content: flex-start;

					image {
						&:nth-child(1) {
							margin-top: 20rpx;
							width: 22rpx;
							margin-left: 20rpx;
						}

						&:nth-child(3) {
							width: 33rpx;
							margin-top: 5rpx;
						}
					}

					text {
						&:nth-child(2) {
							margin-top: 13rpx;
							font-size: 24rpx;
							color: #666666;
							width: 576rpx;
							margin-left: 30rpx;
						}
					}

				}
			}
		}
	}
</style>
